from wand.image import Image
import os


def convert_jp2_to_jpg():
    orignal_path = 'I:\\bookget-1.2.1.windows-amd64\\鐫紫溪蘇先生會纂歷朝紀要旨南綱鑑  二十卷'
    orignalNew_path = 'I:\\bookget-1.2.1.windows-amd64\\test'
    if not os.path.isdir(orignalNew_path):
        os.makedirs(orignalNew_path)
    for ind, file in enumerate(os.listdir(orignal_path)):
        filePath = os.path.join(orignal_path, file)
        with Image(filename=filePath) as img:
            newFile = file.split('.')[0]
            fName = orignalNew_path + '\\' + newFile+'.jpg'
            img.save(filename=fName)


# with Image(filename='I:\\0001.jp2') as img:
#     img.save(filename='I:\\0010.jpg')

convert_jp2_to_jpg()
